package cn.ecut.service.impl;
import java.text.DecimalFormat;
import	java.util.ArrayList;

import cn.ecut.dao.ShenqingdanDao;
import cn.ecut.model.*;
import cn.ecut.service.ShenqingdanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.ImageProducer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class ShenqingdanServiceimpl implements ShenqingdanService {

    @Autowired
    private ShenqingdanDao shenqingdanDao;

    @Override
    public int deleteByPrimaryKey(String danjvbianhao) {
        return shenqingdanDao.deleteByPrimaryKey(danjvbianhao);
    }

    @Override
    public int deleteByYuangonghao(String yuangongHao) {
        return shenqingdanDao.deleteByYuangonghao(yuangongHao);
    }

    @Override
    public int insert(Shenqingdan shenqingdan) {
        return shenqingdanDao.insert(shenqingdan);
    }

    @Override
    public int insertSelective(Shenqingdan record) {
        return shenqingdanDao.insertSelective(record);
    }

    @Override
    public Shenqingdan selectByPrimaryKey(String danjvbianhao) {
        return shenqingdanDao.selectByPrimaryKey(danjvbianhao);
    }

    @Override
    public Shenqingdan selectAllByyuangongHao(String yuangongHao) {
        return shenqingdanDao.selectAllByyuangongHao(yuangongHao);
    }

    @Override
    public int updateByPrimaryKeySelective(Shenqingdan record) {
        return shenqingdanDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Shenqingdan record) {
        return shenqingdanDao.updateByPrimaryKey(record);
    }

    @Override
    public ShenqingdanMessage Changeleixing(Shenqingdan shenqingdan) {
        ShenqingdanMessage shenqingdanMessage = new ShenqingdanMessage();
        shenqingdanMessage.setDanjvbianhao(shenqingdan.getDanjvbianhao());
        shenqingdanMessage.setDanjushenqingriqi(shenqingdan.getDanjushenqingriqi());
        shenqingdanMessage.setShenqingren(shenqingdan.getShenqingren());
        if(shenqingdan.getXinbie() == 1){
            shenqingdanMessage.setXinbie("男");
        }else {
            shenqingdanMessage.setXinbie("女");
        }
        shenqingdanMessage.setSuozaibumem(shenqingdan.getSuozaibumem());
        shenqingdanMessage.setLoudongmingcheng(shenqingdan.getLoudongmingcheng());
        shenqingdanMessage.setLouceng(shenqingdan.getLouceng());
        shenqingdanMessage.setTaofang(shenqingdan.getTaofang());
        shenqingdanMessage.setFangjian(shenqingdan.getFangjian());
        shenqingdanMessage.setPuweibianhao(shenqingdan.getPuweibianhao());
        shenqingdanMessage.setPuweimingcheng(shenqingdan.getPuweimingcheng());
        if(shenqingdan.getDanjuzhuangtai()==0){
            shenqingdanMessage.setDanjuzhuangtai("未审批");
        }else if(shenqingdan.getDanjuzhuangtai() == 1){
            shenqingdanMessage.setDanjuzhuangtai("通过");
        }else {
            shenqingdanMessage.setDanjuzhuangtai("未通过");
        }
        shenqingdanMessage.setYuangonghao(shenqingdan.getYuangonghao());
        return shenqingdanMessage;
    }

    @Override
    public int selectAllCountByyuangongHao(String yuangongHao) {
        return shenqingdanDao.selectAllCountByyuangongHao(yuangongHao);
    }

    public Object getShengqingdanMessqge(ShenqingdanMessage shenqingdanMessage) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        Integer count = 1;//查询符合条件的记录数量。用来在前端显示记录的数量
        List<ShenqingdanMessage> list = new ArrayList();
        list.add(shenqingdanMessage);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", 1);
        map.put("data", list);//dao层查询返回list数据
        return map;
    }

    @Override
    public String getdanjvBianhao() {
        DecimalFormat decimalFormat=new DecimalFormat("00000");
        String s = shenqingdanDao.selectThelast();
        s=s.substring(2);
        System.out.println(s);
        int i=Integer.parseInt(s)+1;
        String k=decimalFormat.format(i);
        String danjvBianhao = "RE"+k;
        System.out.println(danjvBianhao);
        return danjvBianhao;
    }

    @Override
    public Yuangong selectYuangong(String yuangonghao) {
        return shenqingdanDao.selectYuangong(yuangonghao);
    }

    @Override
    public Xiangmu selectXiangmu(String xiangmubianma) {
        return shenqingdanDao.selectXiangmu(xiangmubianma);
    }

    @Override
    public Loudong selectLoudong(String loudongbianma) {
        return shenqingdanDao.selectLoudong(loudongbianma);
    }

    @Override
    public Taofang selectTaofang(String taofangbianma) {
        return shenqingdanDao.selectTaofang(taofangbianma);
    }

    @Override
    public Fangjian selectFangjian(String fangjianbianma) {
        return shenqingdanDao.selectFangjian(fangjianbianma);
    }

    @Override
    public Puwei selectPuwei(String puweibianhao) {
        return shenqingdanDao.selectPuwei(puweibianhao);
    }

    @Override
    public List<Shenqingdan> selectAllshenqingdan() {
        return shenqingdanDao.selectAllshenqingdan();
    }

    @Override
    public int selectAllcount() {
        return shenqingdanDao.selectAllcount();
    }

    @Override
    public List<Shenqingdan> advanceSelect(String s) {
        return shenqingdanDao.advanceSelect(s);
    }

    @Override
    public int updateDanjuzhuangtai(Shenqingdan shenqingdan) {
        return shenqingdanDao.updateDanjuzhuangtai(shenqingdan);
    }

    @Override
    public int updatePuweiShiyongzhuangtai(Puwei puwei) {
        return shenqingdanDao.updatePuweiShiyongzhuangtai(puwei);
    }


}
